<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>评论</title>
<link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>
 <div class="layui-form-item">
    <label class="layui-form-label">评论等级:</label>
    <div class="layui-input-block">
      <div id="test1"></div>
      <input type="hidden" id="commentGrad">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">评论内容:</label>
    <div class="layui-input-block">
      <textarea id="commentContent" required lay-verify="required" placeholder="请输入评论内容" class="layui-textarea"></textarea>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <a href="JavaScript:;" class="layui-btn" id="submit">立即评价</a>
    </div>
  </div>
<script src="../layui/layui.js"></script>
<script src="../res/js/jquery-1.10.2.js"></script>
<script src="../res/js/base.two.js"></script>
 <script>
  layui.use(['rate','layer'], function(){
    var rate = layui.rate
    ,layer = layui.layer;
    var $ = layui.$;
   
    //渲染
    var ins1 = rate.render({
      elem: '#test1'  //绑定元素
      ,text:true
      ,setText: function(value){
    	    var arrs = {
    	    	      '0': ' '
    	    		  ,'1': '极差'
    	    	      ,'2': '差'
    	    	      ,'3': '中等'
    	    	      ,'4': '好'
    	    	      ,'5': '极好'
    	    	    };
    	    	    this.span.text(arrs[value] || ( value + "星"));
    }
    ,choose: function(value){
        $("#commentGrad").val(value);
    }
    });
    
    $("#submit").click(function(){
    	var commentGrad = $("#commentGrad").val();
    	var commentContent = $("#commentContent").val();
    	if(commentGrad == "" || commentGrad == null){
    		layer.msg("请给出评论等级",{time:1000});
    		return ;
    	}else if(commentContent == "" || commentContent == null){
    		layer.msg("请填写评论的内容",{time:1000});
    		return ;
    	}
    	var data = {"proId":getParameter('proId'),"commentGrad":commentGrad,"commentContent":commentContent};
    	var url = "../comment/save.action";
    	$.ajax({
    		url:url,
    		data:data,
    		success:function(msg){
    			
    			if(msg.state == "1"){
    				layer.msg("评论成功!",{icon:1,time:1000},function(){
    					var index = parent.layer.getFrameIndex(window.name);  
    				    parent.layer.close(index);
    				});
    			}else {
    				layer.msg("评论失败!",{icon:2,time:1000},function(){
    					var index = parent.layer.getFrameIndex(window.name);  
    				    parent.layer.close(index);
    				});
    			}
    		}
    	});
    });
    
  });
  </script>
</body>
</html>